Skip to content

fix: stop mutating JsonPath JVM-global defaults#191

Merged
davidgamez merged 1 commit intoMobilityData:masterfrom
entur:fix/jsonpath-global-defaults
Apr 20, 2026
Merged

fix: stop mutating JsonPath JVM-global defaults#191
davidgamez merged 1 commit intoMobilityData:masterfrom
entur:fix/jsonpath-global-defaults

Conversation

@testower
Copy link
Copy Markdown
Collaborator

AbstractVersion's static initializer called Configuration.setDefaults(...) to install JsonOrgJsonProvider as the JVM-wide JsonPath default. Once that class loaded, every other JsonPath user in the same process was forced onto the org.json provider — which only recognises org.json.JSONObject as a map. A consumer using JsonPath against Jackson-parsed maps (e.g. Spring's WebGraphQlTester feeding LinkedHashMap responses to JsonPath) would then fail with PathNotFoundException whenever validator classes happened to load before that consumer first evaluated a path. Class-load order makes the bug intermittent: it surfaces in some test environments but not others.

Replace the global mutation with a SchemaJsonPath facade that exposes a single static parse(Object) returning a DocumentContext bound to a private JsonOrg-configured Configuration. All JsonPath.parse(jsonObject) call sites in AbstractVersion and the rule patchers now route through the facade, so adding a new schema-patching rule cannot accidentally fall back to the default provider.

AbstractVersion's static initializer called Configuration.setDefaults(...)
to install JsonOrgJsonProvider as the JVM-wide JsonPath default. Once that
class loaded, every other JsonPath user in the same process was forced onto
the org.json provider — which only recognises org.json.JSONObject as a map.
A consumer using JsonPath against Jackson-parsed maps (e.g. Spring's
WebGraphQlTester feeding LinkedHashMap responses to JsonPath) would then
fail with PathNotFoundException whenever validator classes happened to load
before that consumer first evaluated a path. Class-load order makes the
bug intermittent: it surfaces in some test environments but not others.

Replace the global mutation with a SchemaJsonPath facade that exposes a
single static parse(Object) returning a DocumentContext bound to a private
JsonOrg-configured Configuration. All JsonPath.parse(jsonObject) call sites
in AbstractVersion and the rule patchers now route through the facade, so
adding a new schema-patching rule cannot accidentally fall back to the
default provider.
@testower testower requested a review from davidgamez April 20, 2026 05:12
Copy link
Copy Markdown
Member

@davidgamez davidgamez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@davidgamez davidgamez merged commit 1591160 into MobilityData:master Apr 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants